﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Observer_WeatherMonitor.Data {
    public class WeatherData : ISubject {
        private ArrayList observers;
        private float temperature;
        private float humidity;
        private float pressure;

        public WeatherData() {
            observers = new ArrayList();
        }

        public void RegisterObserver(IObserver observer) {
            observers.Add(observer);
        }
        public void RemoveObserver(IObserver observer) {
            var i = observers.IndexOf(observer);
            if (i >= 0)
                observers.Remove(observer);
        }
        public void NotifyObservers() {
            foreach (IObserver observer in observers)
                observer.Update(temperature, humidity, pressure);
        }

        public void MeasurementsChanged() {
            NotifyObservers();
        }

        public void SetMeasurements(float temperature, float humidity, float pressure) {
            this.temperature = temperature;
            this.humidity = humidity;
            this.pressure = pressure;
            MeasurementsChanged();
        }
    }
}
